#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define gc() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=gc();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
        x*=f;
    }
    char obuf[BUF],*p3=obuf;
    inline void pc(char ch){
        if(p3-obuf<BUF) *p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    inline void put(const char *s){while(*s) pc(*s),++s;}
    char ch[32];int ctop;
    template<typename T>inline void print(T x){
    	if(x<0) x=~x+1,pc('-');
        if(!x) return pc(48);
        while(x) ch[++ctop]=x%10^48,x/=10;
        while(ctop) pc(ch[ctop--]);
    }
    inline void flush(){fwrite(obuf,p3-obuf,1,stdout);p3=obuf;}
}
using namespace IO;
const int N=4005,mod=999999999;
int n,q;
int B1,k1[N],L1[N],R1[N];
int B2,k2[N],L2[N],R2[N];
struct BIT{
	int t[N];
	inline void add(int x,int y){for(;x<=n;x+=x&-x) t[x]+=y;}
	inline int query(int x){
		int ans=0;
		for(;x;x-=x&-x) ans+=t[x];
		return ans;
	}
}T[128];
struct node{
	int sum[100],a[N];
	inline void add(int x,int y){
		a[x]+=y;
		sum[k2[x]]+=y;
	}
	inline int query(int x){
		int ans=0;
		for(int i=1;i<k2[x];++i) ans+=sum[i];
		for(int i=L2[k2[x]];i<=x;++i) ans+=a[i];
		return ans;
	}
}F[N];
int tmp[N];
inline int calc(int x,int si,int w){
	if(si==1) return x&w;
	if(si==2) return x|w;
	if(si==3) return x^w;
	return (x+w)%mod;
}
signed main(){
	freopen("fire.in","r",stdin);
	freopen("fire.out","w",stdout);
	read(n),read(q);
	B1=max(1ll,(int)pow(n*log2(n),0.33333));
	B2=sqrt(n);
	for(int i=1;i<=n;++i){
		k1[i]=(i-1)/B1+1;
		k2[i]=(i-1)/B2+1;
		if(!L1[k1[i]]) L1[k1[i]]=i;
		if(!L2[k2[i]]) L2[k2[i]]=i;
		R1[k1[i]]=R2[k2[i]]=i;
	}
	while(q--){
		int op;read(op);
		if(op==1){
			int dir,x,si,w;
			read(dir),read(x),read(si),read(w);
			if(dir==0){
				for(int i=1;i<=n;++i){
					tmp[i]=calc(F[x].a[i],si,w)-F[x].a[i];
					F[x].add(i,tmp[i]);
				}
				for(int i=1;i<=n;++i){
					if(i+(i&-i)<=n) tmp[i+(i&-i)]+=tmp[i];
					T[k1[x]].t[i]+=tmp[i];
				}
			}else{
				for(int j=1;j<=k1[n];++j){
					int sum=0;
					for(int i=L1[j];i<=R1[j];++i){
						int d=calc(F[i].a[x],si,w)-F[i].a[x];
						F[i].add(x,d);
						sum+=d;
					}
					T[j].add(x,sum);
				}
			}
		}else{
			int x,y;read(x),read(y);
			int ans=0;
			for(int i=1;i<k1[x];++i) ans+=T[i].query(y);
			for(int i=L1[k1[x]];i<=x;++i) ans+=F[i].query(y);
			print(ans),pc('\n');
		}
	}
	flush();
	return 0;
}


